import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
import LegalInfo from '../views/LegalInfo.vue'
import Consultation from '../views/Consultation.vue'
import CaseAssistance from '../views/CaseAssistance.vue'
import NotFound from '../views/NotFound.vue' // 引入 NotFound 组件
import holyGrailLayout from '../views/holyGrailLayout.vue'

const routes = [

    {
        path: '/',
        component: holyGrailLayout,
        children: [
            {path: '/', component: Home},
            {path: '/about', component: About},
            {path: '/legal-info', component: LegalInfo},
            {path: '/consultation', component: Consultation},
            {path: '/case-assistance', component: CaseAssistance},
        ]
    },

    {
        path: '/:pathMatch(.*)*', // 404 路由捕获
        name: 'NotFound',
        component: NotFound
    }

]
// const routes = [
//     {
//         path: '/',
//         component: Main,
//         redirect: '/home',
//         children: [
//             {path: '/home',name: 'Home',component: Home},
//             {path: '/consultation',name: 'Consult',component: Consult},
//             {path: '/cases',name: 'Cases',component: Cases},
//             {path: '/product',name: 'Product',component: Product},
//             {path: '/users',name: 'Users',component: User},
//             {path: '/about',name: 'About',component: About}
//         ]
//     }
// ]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
    // 可以在这里添加一些逻辑，例如权限验证等
    next()
})

// 全局错误处理
router.onError((error) => {
    console.error('路由错误:', error)
})

export default router